package com.hgy.hhao.springboot_vue.controller;

import com.hgy.hhao.springboot_vue.pojo.User;
import com.hgy.hhao.springboot_vue.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author HhaoAn
 * @date 2025年03月02日 21:31
 */
@RestController
@CrossOrigin//支持跨域请求（Vue项目,vscode）
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/user/getUserById")
    public String getUserById(Integer id) {
        return userService.getUserById(id).toString();
    }

    @RequestMapping("/user/deleteById")
    public String deleteById(Integer id) {
        userService.deleteById(id);
        return "删除成功";
    }

    @RequestMapping("/user/getUserByIdv")
    public User getUserByIdv(Integer id) {
        return userService.getUserById(id);
    }
    @RequestMapping("/user/getAll")
    public List<User> getAll() {
        return userService.getAll();
    }

    @RequestMapping("/user/getAllByGender")
    public List<User> getAllByGender(Integer gender) {
        return userService.getAllByGender(gender);
    }

    @RequestMapping("/user/saveUser")
    public String saveUser(@RequestBody User user) {
        userService.saveUser(user);
        return "保存成功";
    }
}
